﻿@{
    ViewBag.Title = "Index";
}

@section scripts{
    <script type="text/javascript">
        $(f_init);
        var dialog = frameElement.dialog; //调用页面的dialog对象(ligerui对象)        var dialogData = dialog.get('data');//获取data参数
        var callback = dialogData.callback;

        var form = null, formData = null, id = getQueryString("id");
        
        function f_init() {
            form = $("#mainform").ligerForm({
                fields: [
                    { name: 'UserNo', label: '用户编码', type: 'text' },
                    { name: 'UserName', label: '用户名', type: 'text' },
                      { name: 'UserPassword', label: '密码', type: 'text' },
                    { name: 'CreateUserID', label: '加入时间', type: 'date' }
                ],
                buttons: [ 
                     { click: save, text: '保存' },
                     { click: cancel, text: '取消' }
                ]
            });
            loadForm();
        }

        function loadForm() {
            if (id) {
                $.getJSON('@Url.Content("~/System/GetUserDetailData/")' + id, function (data) {
                    formData = data;
                    form.setData(formData);
                });
            }
        } 
        function save()
        { 
            var data = form.getData();
            var postData = $.extend({}, formData, data);
            $.ajax({
                url: '@Url.Content("~/System/SaveUser/")',
                type: 'post',
                dataType: 'json',
                data: postData,
                beforeSend: function(){
                    $.ligerDialog.waitting("保存中...");
                },
                success: function (result) {
                    $.ligerDialog.closeWaitting();
                    if (result.Success) {
                        $.ligerDialog.success("保存成功");
                        if (callback) callback();
                    } else {
                        $.ligerDialog.error("保存失败");
                    }
                }
            });
        }
        function cancel()
        {
            dialog.close();//关闭dialog  
        }
        function getQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = location.search.substr(1).match(reg);
            if (r != null) return unescape(decodeURI(r[2])); return null;
        }
    </script> 
    <style type="text/css">
        .l-toolbar {
            background:none;
            height: 32px;
            border: 1px solid #D3d3d3; background:#f3f2f2;
        }

    </style>
}
  
<div id="mainform" style="margin:8px;"></div> 